import { Inject, Provide } from '@midwayjs/decorator';
import { BaseService } from '@cool-midway/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { AppComplainEntity } from '../entity/complain';
import { UserInfoService } from '../../user/service/info';
import * as moment from 'moment';

/**
 * 意见反馈
 */
@Provide()
export class AppComplainService extends BaseService {
  @InjectEntityModel(AppComplainEntity)
  appComplainEntity: Repository<AppComplainEntity>;

  @Inject()
  ctx;

  @Inject()
  UserInfoService: UserInfoService;

  /**
   * 提交
   * @param info
   */
  async submit(info: AppComplainEntity) {
    await this.appComplainEntity.insert(info);
  }

  /**
   * 更新
   * @param param
   */
  async update(param: AppComplainEntity) {
    if (param.status == 1) {
      param.handlerId = this.ctx.admin.userId;
    }
    this.UserInfoService.sendPushMessage([param.userId], "意见反馈", param.remark,{
      type: 'complain',
      title:"意见反馈",
      content:param.remark,
      id:param.id
    })
    let data={
      time2:{
        value:moment().format('yyyy-MM-DD HH:mm:ss'),
      },
      thing3:{
        value:param.content
      },
      thing4:{
        value:param.remark
      }
    }
    this.UserInfoService.sendMiMessage(param.userId, "HNeNBG3ssLpsMabaCjEyTQugzj0pFzkIaQopv_wynUo",'complain',data,param.id)
    await super.update(param);
  }
}
